package com.dabai.qrcodescanlibrary;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.dabai.qrcodescan.qrcode.QRCodeScanUtils;

public class MainActivity extends AppCompatActivity {

    private Button mButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initViews();



        mButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                QRCodeScanUtils.startQrCodeScanner(MainActivity.this, 201);
            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == 201) {
                if (data != null) {

                    Toast.makeText(this, "" + QRCodeScanUtils.getQrCodeScannerResult(data), Toast.LENGTH_SHORT).show();

                }
            }
        }

    }

    private void initViews() {
        mButton = findViewById(R.id.button);
    }
}